/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ejb.persistence;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author Julien
 */
@Entity
@Table(name="USER")
@NamedQueries({
        @NamedQuery(name="User.exists", query="SELECT u FROM User u WHERE u.userAuth = :userAuth"),
        @NamedQuery(name="User.inscription", query="SELECT u FROM User u WHERE u.userAuth.login = :userlog")})
public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="ID_USER")
    private Long id;

    @Column(name="First_Name")
    private String firstName;
    
    @Column(name="Last_Name")
    private String lastName;
    
    @Column(name="Email")
    private String email;
    
    @Embedded
    private UserAuthentication userAuth;
    
    @Column(name="Types")
    @Enumerated(EnumType.STRING)
    private UserType type = UserType.Utilisateur;
    
    @OneToMany(mappedBy = "user", fetch= FetchType.EAGER)
    private List<Order> orders;
    
    @OneToOne(mappedBy = "user")
    private Address address;
    
/* -----------------------------------------------------------------------------
 * ---------------------------GETTERS AND SETTERS-------------------------------
 * ---------------------------------------------------------------------------*/    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public UserAuthentication getUserAuth() {
        return userAuth;
    }

    public void setUserAuth(UserAuthentication UserAuth) {
        this.userAuth = UserAuth;
    }

    public UserType getType() {
        return type;
    }

    public void setType(UserType type) {
        this.type = type;
    }

    public List<Order> getOrders() {
        return orders;
    }

    public void setOrders(List<Order> orders) {
        this.orders = orders;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }
    
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ejb.persistence.User[ id=" + id + 
                                        " | firstName= "+ firstName +
                                        " | lastName= "+ lastName +
                                        " | email= "+ email +
                                        " | type= "+ type +
                                        " | userAuth= "+ userAuth.toString() +
                                        " | orders= "+ orders.toString() +
                                        " | address= "+ address.toString() +
                "]";
    }
    
}
